﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using Moonwish.Core.DataAccess;
using Moonwish.Foundation.DataEntity;

namespace Moonwish.Foundation.DataAccess.SqlServer.ValueObjectClassCmd
{
    public class DeleteCommand : SqlStringCommand<T_FDT_ValueObjectClass>
    {
        public DeleteCommand(DbContext dbContext, List<string> ids, string userId)
            : base(dbContext, ids, userId)
        {
        }

        public override void Execute()
        {
            var count = DbTable.Count(
                        obj => Ids.Contains(obj.ValueObjectClassId) && obj.DataStatus == "New");
            if (count != Ids.Count)
            {
                throw new InvalidOperationException(String.Format("删除集合中包含了无法定位的值对象Id。"));
            }
            DbContext.Database.ExecuteSqlCommand(
                    string.Format(
                        "delete from [T_FDT_ValueObjectClass] where ValueObjectClassId in ('{0}')",
                        string.Join("','", Ids)));
        }
    }
}
